package com.base.doublepoint;


public class ReverseVowels {
    /**
     * 345. 反转字符串中的元音字母
     * 编写一个函数，以字符串作为输入，反转该字符串中的元音字母。
     *
     * @param s description:字符串参数
     * @return
     * @author li
     */

    public String reverseVowels(String s) {

        int n = s.length();
        int left = 0, right = n - 1;
        char[] sChar = s.toCharArray();

        while (left < right) {

            char a = sChar[left];
            char b = sChar[right];

            if (isNotVowel(a)) {

                left++;
                continue;
            } else if (isNotVowel(b)) {

                right--;
                continue;
            } else {

                char c = sChar[left];
                sChar[left] = sChar[right];
                sChar[right] = c;
            }
            left++;
            right--;
        }
        return new String(sChar);
    }

    private boolean isNotVowel(char c) {
        /*
         *判断是否是原音字符
         */
        return c != 'a' && c != 'o' && c != 'e' && c != 'i' && c != 'u' && c != 'A' &&
                c != 'O' && c != 'E' && c != 'I' && c != 'U';
    }
}

